﻿using System;

namespace Close.io.API
{
	public interface IDateExpression
	{
		string GetKey();
		string GetValue();
	}

	public abstract class DateExpression : IDateExpression
	{
		protected DateExpression( string fieldName)
		{
			_fieldName = fieldName;
		}

		private const string lessThan = "lt";
		private const string lessThanEqual = "lte";
		private const string greaterThan = "gt";
		private const string greaterThanEqual = "gte";
		 

		private DateTime _dateTime;
		private string _suffix;
		private string _fieldName;
		public void LessThan(DateTime dateTime)
		{
			_dateTime = dateTime;
			_suffix = lessThan;
		}

		public void LessThanOrEqualTo(DateTime dateTime)
		{
			_dateTime = dateTime;
			_suffix = lessThanEqual;

		}

		public void GreaterThan(DateTime dateTime)
		{
			_dateTime = dateTime;
			_suffix = greaterThan;
		}

		public void GreaterThanOrEqualTo(DateTime dateTime)
		{
			_dateTime = dateTime;
			_suffix = greaterThanEqual;
		}

		public override string ToString()
		{
			return string.Format("{0}__{1}={2}", _fieldName, _suffix, _dateTime.ToString("s"));
		}

		public string GetKey()
		{
			return string.Format("{0}__{1}", _fieldName, _suffix);
		}

		public string GetValue()
		{
			return _dateTime.ToString("s");
		}

		public class DueDateExpression : DateExpression
		{
			public DueDateExpression()
				: base("due_date")
			{

			}
		}
		public class DateCreatedExpression : DateExpression
		{
			public DateCreatedExpression()
				: base("date_created")
			{

			}
		}
		public class DateUpdatedExpression : DateExpression
		{
			public DateUpdatedExpression()
				: base("date_updated")
			{

			}
		}
		public class DateWonExpression : DateExpression
		{
			public DateWonExpression()
				: base("date_won")
			{

			}
		}
	 

	}
}